﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace HengTong.DataAccess.Migrations
{
    /// <inheritdoc />
    public partial class 退休办理离职办理合同续签增加人员选择Guid : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            // 现有的删除外键和索引操作...
            
            migrationBuilder.DropForeignKey(
                name: "FK_SysHrRenewRequestBill_SysPersonContract_PersonContractId",
                table: "SysHrRenewRequestBill");

            migrationBuilder.DropForeignKey(
                name: "FK_SysHrTransferRequestBill_SysPerson_PersonId",
                table: "SysHrTransferRequestBill");

            migrationBuilder.DropIndex(
                name: "IX_SysHrRenewRequestBill_PersonContractId",
                table: "SysHrRenewRequestBill");

            migrationBuilder.AlterColumn<Guid>(
                name: "PersonId",
                table: "SysHrTransferRequestBill",
                type: "uniqueidentifier",
                nullable: false,
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"),
                oldClrType: typeof(Guid),
                oldType: "uniqueidentifier",
                oldNullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Name",
                table: "SysHrTransferRequestBill",
                type: "nvarchar(128)",
                maxLength: 128,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "StaffNo",
                table: "SysHrTransferRequestBill",
                type: "nvarchar(128)",
                maxLength: 128,
                nullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "StaffNo",
                table: "SysHrRetireRequestBill",
                type: "nvarchar(128)",
                maxLength: 128,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(128)",
                oldMaxLength: 128);

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "SysHrRetireRequestBill",
                type: "nvarchar(128)",
                maxLength: 128,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(128)",
                oldMaxLength: 128);

            migrationBuilder.AddColumn<Guid>(
                name: "PersonId",
                table: "SysHrRetireRequestBill",
                type: "uniqueidentifier",
                nullable: false,
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));

            migrationBuilder.AlterColumn<string>(
                name: "StaffNo",
                table: "SysHrResignRequestBill",
                type: "nvarchar(128)",
                maxLength: 128,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(128)",
                oldMaxLength: 128);

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "SysHrResignRequestBill",
                type: "nvarchar(128)",
                maxLength: 128,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(128)",
                oldMaxLength: 128);

            migrationBuilder.AddColumn<Guid>(
                name: "PersonId",
                table: "SysHrResignRequestBill",
                type: "uniqueidentifier",
                nullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "StaffNo",
                table: "SysHrRenewRequestBill",
                type: "nvarchar(128)",
                maxLength: 128,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(128)",
                oldMaxLength: 128);

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "SysHrRenewRequestBill",
                type: "nvarchar(128)",
                maxLength: 128,
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(128)",
                oldMaxLength: 128);

            migrationBuilder.AddColumn<Guid>(
                name: "PersonId",
                table: "SysHrRenewRequestBill",
                type: "uniqueidentifier",
                nullable: false,
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));

            migrationBuilder.AddColumn<string>(
                name: "Name",
                table: "SysHrDismissRequestBill",
                type: "nvarchar(128)",
                maxLength: 128,
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "StaffNo",
                table: "SysHrDismissRequestBill",
                type: "nvarchar(128)",
                maxLength: 128,
                nullable: true);

            migrationBuilder.CreateIndex(
                name: "IX_SysHrRetireRequestBill_PersonId",
                table: "SysHrRetireRequestBill",
                column: "PersonId");

            migrationBuilder.CreateIndex(
                name: "IX_SysHrResignRequestBill_PersonId",
                table: "SysHrResignRequestBill",
                column: "PersonId");

            migrationBuilder.CreateIndex(
                name: "IX_SysHrRenewRequestBill_PersonContractId",
                table: "SysHrRenewRequestBill",
                column: "PersonContractId",
                unique: true,
                filter: "[PersonContractId] IS NOT NULL");

            migrationBuilder.CreateIndex(
                name: "IX_SysHrRenewRequestBill_PersonId",
                table: "SysHrRenewRequestBill",
                column: "PersonId");

            migrationBuilder.AddForeignKey(
                name: "FK_SysHrRenewRequestBill_SysPersonContract_PersonContractId",
                table: "SysHrRenewRequestBill",
                column: "PersonContractId",
                principalTable: "SysPersonContract",
                principalColumn: "ID",
                onDelete: ReferentialAction.SetNull);

            migrationBuilder.AddForeignKey(
                name: "FK_SysHrRenewRequestBill_SysPerson_PersonId",
                table: "SysHrRenewRequestBill",
                column: "PersonId",
                principalTable: "SysPerson",
                principalColumn: "ID",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_SysHrResignRequestBill_SysPerson_PersonId",
                table: "SysHrResignRequestBill",
                column: "PersonId",
                principalTable: "SysPerson",
                principalColumn: "ID",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_SysHrRetireRequestBill_SysPerson_PersonId",
                table: "SysHrRetireRequestBill",
                column: "PersonId",
                principalTable: "SysPerson",
                principalColumn: "ID",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_SysHrTransferRequestBill_SysPerson_PersonId",
                table: "SysHrTransferRequestBill",
                column: "PersonId",
                principalTable: "SysPerson",
                principalColumn: "ID",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_SysHrRenewRequestBill_SysPersonContract_PersonContractId",
                table: "SysHrRenewRequestBill");

            migrationBuilder.DropForeignKey(
                name: "FK_SysHrRenewRequestBill_SysPerson_PersonId",
                table: "SysHrRenewRequestBill");

            migrationBuilder.DropForeignKey(
                name: "FK_SysHrResignRequestBill_SysPerson_PersonId",
                table: "SysHrResignRequestBill");

            migrationBuilder.DropForeignKey(
                name: "FK_SysHrRetireRequestBill_SysPerson_PersonId",
                table: "SysHrRetireRequestBill");

            migrationBuilder.DropForeignKey(
                name: "FK_SysHrTransferRequestBill_SysPerson_PersonId",
                table: "SysHrTransferRequestBill");

            migrationBuilder.DropIndex(
                name: "IX_SysHrRetireRequestBill_PersonId",
                table: "SysHrRetireRequestBill");

            migrationBuilder.DropIndex(
                name: "IX_SysHrResignRequestBill_PersonId",
                table: "SysHrResignRequestBill");

            migrationBuilder.DropIndex(
                name: "IX_SysHrRenewRequestBill_PersonContractId",
                table: "SysHrRenewRequestBill");

            migrationBuilder.DropIndex(
                name: "IX_SysHrRenewRequestBill_PersonId",
                table: "SysHrRenewRequestBill");

            migrationBuilder.DropColumn(
                name: "Name",
                table: "SysHrTransferRequestBill");

            migrationBuilder.DropColumn(
                name: "StaffNo",
                table: "SysHrTransferRequestBill");

            migrationBuilder.DropColumn(
                name: "PersonId",
                table: "SysHrRetireRequestBill");

            migrationBuilder.DropColumn(
                name: "PersonId",
                table: "SysHrResignRequestBill");

            migrationBuilder.DropColumn(
                name: "PersonId",
                table: "SysHrRenewRequestBill");

            migrationBuilder.DropColumn(
                name: "Name",
                table: "SysHrDismissRequestBill");

            migrationBuilder.DropColumn(
                name: "StaffNo",
                table: "SysHrDismissRequestBill");

            migrationBuilder.AlterColumn<Guid>(
                name: "PersonId",
                table: "SysHrTransferRequestBill",
                type: "uniqueidentifier",
                nullable: true,
                oldClrType: typeof(Guid),
                oldType: "uniqueidentifier");

            migrationBuilder.AlterColumn<string>(
                name: "StaffNo",
                table: "SysHrRetireRequestBill",
                type: "nvarchar(128)",
                maxLength: 128,
                nullable: false,
                defaultValue: "",
                oldClrType: typeof(string),
                oldType: "nvarchar(128)",
                oldMaxLength: 128,
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "SysHrRetireRequestBill",
                type: "nvarchar(128)",
                maxLength: 128,
                nullable: false,
                defaultValue: "",
                oldClrType: typeof(string),
                oldType: "nvarchar(128)",
                oldMaxLength: 128,
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "StaffNo",
                table: "SysHrResignRequestBill",
                type: "nvarchar(128)",
                maxLength: 128,
                nullable: false,
                defaultValue: "",
                oldClrType: typeof(string),
                oldType: "nvarchar(128)",
                oldMaxLength: 128,
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "SysHrResignRequestBill",
                type: "nvarchar(128)",
                maxLength: 128,
                nullable: false,
                defaultValue: "",
                oldClrType: typeof(string),
                oldType: "nvarchar(128)",
                oldMaxLength: 128,
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "StaffNo",
                table: "SysHrRenewRequestBill",
                type: "nvarchar(128)",
                maxLength: 128,
                nullable: false,
                defaultValue: "",
                oldClrType: typeof(string),
                oldType: "nvarchar(128)",
                oldMaxLength: 128,
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "SysHrRenewRequestBill",
                type: "nvarchar(128)",
                maxLength: 128,
                nullable: false,
                defaultValue: "",
                oldClrType: typeof(string),
                oldType: "nvarchar(128)",
                oldMaxLength: 128,
                oldNullable: true);

            migrationBuilder.CreateIndex(
                name: "IX_SysHrRenewRequestBill_PersonContractId",
                table: "SysHrRenewRequestBill",
                column: "PersonContractId");

            migrationBuilder.AddForeignKey(
                name: "FK_SysHrRenewRequestBill_SysPersonContract_PersonContractId",
                table: "SysHrRenewRequestBill",
                column: "PersonContractId",
                principalTable: "SysPersonContract",
                principalColumn: "ID");

            migrationBuilder.AddForeignKey(
                name: "FK_SysHrTransferRequestBill_SysPerson_PersonId",
                table: "SysHrTransferRequestBill",
                column: "PersonId",
                principalTable: "SysPerson",
                principalColumn: "ID");
        }
    }
}
